<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    {load href='/static/css/bootstrap.css'}
    {load href='/static/css/all.css'}
    {load href='/static/js/jquery-3.4.1.min.js'}
    {load href='/static/js/bootstrap.min.js'}
    {load href='/static/js/bootbox.min.js'}
    <style>
        body{font-size: 12px}
        .pagination{float:right}
        .pagination>li{margin-left: 4px;}
        .btn{
            width: 80px; /* 设置按钮宽度为 80 像素，可根据实际需求调整数值 */
            height: 30px; /* 设置按钮高度为 30 像素，可根据实际需求调整数值 */
            font-size: 12px; /* 同时可以适当调小按钮文字的字体大小，让整体更协调 */
            padding: 5px 10px;
        }
        .form-control{
            height: 30px;
        }
    </style>
</head>
<body>
<div class="container-furid" style="padding: 0px">
    <table class="table table-hover">
        <tr><th>ID</th><th>科室名</th><th>地址</th><th>操作</th></tr>
        {volist name='data' id='v'}
        <tr><td>{$v.subjectid}</td><td>{$v.subjectname}</td><td>{$v.address}</td>
            <td><button class="btn btn-primary btn-edit" data-toggle='modal' data-target='#editsubjectModal' data-backdrop='static' onclick="edit({$v.id})"><span class="fa fa-edit"></span>修改</button>&nbsp;&nbsp;<button class="btn btn-danger" onclick="del({$v.id})"><span class="fa fa-trash-alt"></span>&nbsp;删除</button></td></tr>
        {/volist}
    </table>
    {$data|raw}
</div>

</body>
</html>
<div class="modal" id="editsubjectModal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <div class="modal-title">修改科室信息</div>
                <button class="close" data-dismiss='modal'>&times;</button>
            </div>
            <div class="modal-body">
                <form action="" id="editsubjectForm">
                    <input type="hidden" id="id" name="id">
                    <div class="form-group">
                        <div class="row">
                            <div class="col-sm-4">
                                <label for="did">ID：</label>
                                <input type="text" class="form-control" id="did" name="subjectid">
                            </div>
                            <div class="col-sm-4">
                                <label for="name">科室名：</label>
                                <input type="text" class="form-control" id="name" name="subjectname">
                            </div>
                            <div class="col-sm-4">
                                <label for="address">地址：</label>
                                <input type="text" class="form-control" id="address" name="address">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="update()">保存</button>
            </div>
        </div>
    </div>
</div>

<script>
    function del(id){
        bootbox.confirm("确实要删除该记录吗",function(res){
            if(res){
                $.get("/index.php/hospital/subjectc/del",{'id':id},function(res1){
                    if(res1==1){
                        bootbox.alert("删除记录成功",function(){
                            window.location.reload();
                        })
                    }
                })
            }
        })
    }

    function edit(id){
        $.get("/index.php/hospital/subjectc/edit",{'id':id},function(res){
            $("#id").val(res.id);
            $("#did").val(res.subjectid);
            $("#name").val(res.subjectname);
            $("#address").val(res.address);
        });
    }

    function update(){
        $.post("/index.php/hospital/subjectc/update",$("#editsubjectForm").serialize(),function(res){
            if(res==1){
                bootbox.alert("修改成功",function(){
                    window.location.reload();
                })
            }else{
                bootbox.alert("修改失败");
            }
        });
    }
</script>